package com.telit.firecommand.task;

import cn.hutool.core.util.IdUtil;
import com.telit.common.util.LogUtil;
import com.telit.firecommand.service.FireAlarmPromptTaskService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * Create by Chencf 2022/10/29
 */

@Slf4j
@Component
public class FireAlarmPromptTask {

    public static final String FIRE_WARNING_TONE = "fireAlarmPromptTask.warningTone";
    public static final String FIRE_WARNING_TONE_XXL_JOB = "fireAlarmPromptTaskWarningTone";
    public static final String TEST = "test";

    @Autowired
    private FireAlarmPromptTaskService fireAlarmPromptTaskService;

//    @XxlJob(FIRE_WARNING_TONE_XXL_JOB)
//    @Scheduled(cron = "${task.firetask.fireAlarmPromptTask.warningTone}")
    public void statisticOfMonth() {

        String taskName ="火情报警提示task";

        String requiredId = IdUtil.fastSimpleUUID();
        // 获取分布式锁，防止并发执行
        LogUtil.taskLogBegin(log, taskName, requiredId);
//        if (!LockUtil.lock(FIRE_WARNING_TONE, requiredId, 360)) {
//            LogUtil.taskLogUnLock(log, taskName, requiredId, FIRE_WARNING_TONE);
//            return;
//        }
        try {
            //执行提示的业务逻辑
            fireAlarmPromptTaskService.warningTone();

        } catch (Exception e) {
            log.error(taskName + " 执行失败！", e);
//        } finally {
//            LockUtil.unLock(FIRE_WARNING_TONE, requiredId);
        }
        LogUtil.taskLogEnd(log, taskName, requiredId);
    }


    @XxlJob(TEST)
    public void test() {
        log.info("xxl--job  执行成功");
        System.out.println("FIRE_WARNING_TONE = " + FIRE_WARNING_TONE);
    }



}
